package servlets;

import java.io.IOException;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.Billet;
import dao.DaoBillet;

/**
 * Servlet implementation class CreateBillet
 */
public class CreateBillet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public CreateBillet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		int idutilisateur = 1;

		String villeDepart = request.getParameter("villedepart");
		String villeArrivee = request.getParameter("villearrivee");
		String dateDepart = request.getParameter("datedepart");
		String heureDepart = request.getParameter("heuredepart");
		//TODO Avoir heure
		//String heureArrivee = request.getParameter("heurearrivee");
		double prixInitial = Double.parseDouble(request.getParameter("prixinitial"));
		double prixVente = Double.parseDouble(request.getParameter("prixvente"));
		String dateValide = request.getParameter("validitebillet");
		String imageBillet = request.getParameter("imagebillet");
		
		String rib_banque = request.getParameter("rib_banque");
		String rib_compte = request.getParameter("rib_compte");
		String rib_cle = request.getParameter("rib_cle");
		String rib_guichet = request.getParameter("rib_guichet");
		
		System.out.println(villeDepart);

		Billet billet = new Billet();
		billet.setDateDepart(dateDepart);
		billet.setDateValidation(null);
		billet.setEtatBillet("non_vendu");
		billet.setHeureDepart(heureDepart);
		billet.setIdutilisateur(idutilisateur);
		billet.setImageBillet(imageBillet);
		billet.setPrixInitial(prixInitial);
		billet.setPrixVente(prixVente);
		
		billet.setRibBanque(rib_banque);
		billet.setRibCle(rib_cle);
		billet.setRibCompte(rib_compte);
		billet.setRibGuichet(rib_guichet);
		
		billet.setValiditeBillet(dateValide);
		billet.setVilleArrivee(villeArrivee);
		billet.setVilleDepart(villeDepart);
		
		DaoBillet daoBillet = new DaoBillet();
		daoBillet.create(billet);

        request.getRequestDispatcher( "/messages.jsp?billet=create").forward( request, response );
	}

}
